package com.stu.spring.context.chapter04;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

public class CustonTagBeanBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

	// CustonTagBean 对应的类
	@Override
	protected Class<?> getBeanClass(Element element) {
		return CustonTagBean.class;
	}

	// 从 element 中解析并提取对应的元素
	@Override
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String name = element.getAttribute("name");
		String realName = element.getAttribute("realName");
		// 将提取的数据放入到 BeanDefinitionBuilder 中，待到完成所有 bean 的解析后统一注册到 beanFactory 中
		if(StringUtils.hasText(name)){
			builder.addPropertyValue("name", name);
		}
		if(StringUtils.hasText(realName)){
			builder.addPropertyValue("realName", realName);
		}
	}

}
